It is common in many microprocessor applications which require the performance of specific tasks at certain times to use processor timers to time such events. The generation of a square wave signal which is used for pulse width modulation ("PWM") DC motor control is one example of where the timer is used. Processor timers are also used as interval or "watchdog" timers to keep track of the time elapsed since the occurrence of a certain event. After a predetermined time period has elapsed the watchdog timer notifies the processor so that appropriate action may be taken. A processor timer may also be used to generate periodic interrupts. This sort of timer function is useful in real time applications such as data sampling and communications.
Microprocessor timers of the prior art which have been used to produce repeated interrupts are typically counters which provide an interrupt when the counter overflows, or in the case of a countdown timer, when the counter reaches zero. In these types of timers, a countdown counter is typically loaded with a start value by the processor. The clock signal to the counter causes the counter to count down from its start value to zero. The larger the start value loaded into the counter, the longer the countdown period. When the counter counts down to zero, a zero comparator interrupts the processor. In order to begin timing the next interrupt the counter must be reloaded with a new start value. This requires the processor to execute a series of instructions in order to reload the counter and restart the timer, thereby adding an inherent delay to the timing interval and reducing the accuracy of the timer. The inherent delay cannot be factored into the countdown period because the delays are unpredictable due to variations in processor speed caused by congestion from the execution of other applications.
Microprocessor timers also often employ a "prescaler" in order to lengthen the timing period. The prescaler is usually a divide-by counter which increments the counter only after a given number of input clock ticks. Reading the prescaler could be a useful way of determining the number of cycles elapsed since the timer was finished so that the subsequent timing period may be adjusted accordingly. However, in the usual implementation of a clock and prescaler, the prescaler is cleared any time the timer is written to, so this useful information is lost.
Because of the above deficiencies, special dedicated timer hardware is often designed for specific applications so that the application does not have to rely on the inaccurate microprocessor timer. This need for special dedicated hardware can add to the cost and complexity of an application.
Timers are used in applications where it is desired to create or time pulse width modulated signals. PWM signals are used in communications, dc motor control and other applications. In dc motor control the duty cycle of the PWM signal controls the torque or speed of the motor. A timer can be used to generate a PWM signal having a specified duty cycle. A timer may also be used to measure the width of incoming PWM pulses. Timers of the prior art that have been used for PWM applications have exhibited the same deficiencies as are seen in interval timers of the prior art.
As can be seen from the above, a microprocessor timer capable of generating accurately timed interrupts, generating accurate PWM signals and accurately measuring PWM signals without the need for special dedicated application hardware is desirable.